package org.alex.netShop.pages;



import org.alex.netShop.interfaces.Seller;
import org.alex.netShop.interfaces.Sellers;
import org.alex.netShop.interfaces.User;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;

public class ViewSeller
{
	@Inject
	@Property
	private Sellers sellers;

	@Property
	@Persist
	private Seller currentSeller;

	@InjectPage
	private SellerDetails sellerDetailsPage;
	
	@InjectPage
	private AddPurchase addPurchase;
	
	@OnEvent(component = "sellerDetailsLink")
	Object onShowDetails(String name) {
		Seller chosenSeller = sellers.retrieveSeller(name);
		sellerDetailsPage.setChosenSeller(currentSeller);
		return sellerDetailsPage;
	}
	@OnEvent(component = "addSellerLink")
	Object onSellerLink(String name) {

		addPurchase.setPurchaseSeller(name);
		return addPurchase;
	}
	@SessionState
	private User user;

	private boolean userExists;
	
	public User getUser() {
		return user;
	}
	
	Object onActivate() {
		if (!userExists) return Login.class;
		return null;
	}

}
